package com.atguigu.dailyservice.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.dailyservice.service.StatisticsDailyService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author test.java
 * @since 2023-03-25
 */

@RestController
@RequestMapping("/dailyservice/statistics-daily")
@CrossOrigin
public class StatisticsDailyController {

	@Resource
	private StatisticsDailyService statisticsDailyService;

   //统计每天注册用户并保存到数据库
	@PostMapping("registerCount/{date}")
	public Result createStatisticsByDate(@PathVariable String date) {
		statisticsDailyService
				.createStatisticsByDay(date);
		return Result.ok();
	}

     //图表显示，返回两部分数据，日期json数组，数量数组
	@GetMapping("show-chart/{begin}/{end}/{type}")
	public Result showChart(@PathVariable String begin, @PathVariable String end, @PathVariable String type){
		Map<String, Object> map = statisticsDailyService.getChartData(begin, end, type);
		return Result.ok().data(map);
	}

}

